package org.jackysoft.struts2.admin;

import java.util.Collection;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Namespace;
import org.jackysoft.annotations.Logger;
import org.jackysoft.entity.Department;
import org.jackysoft.service.DepartmentService;
import org.jackysoft.struts2.UtilsCRUDAction;
import org.jackysoft.util.OperationType;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

@Controller
@Namespace("/admin/department")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
@Logger(label="部门",logType=OperationType.System)
public class DepartmentAction extends UtilsCRUDAction<Department> {
	/**
	 * 
	 */
	private static final long serialVersionUID = -320200352198356156L;
	private DepartmentService service;
	private Department bean;
	private Collection<Department> beans;
	
	
	
	
	public String room() throws Exception{
		if(bean==null){
			bean = getLoginUser().getDepartment();
		}
		beans = service.getChildren(bean);
		return "room";
		
	}
	
	public String byroot() throws Exception{
		beans = service.getChildren("root");
		return BEANLIST;
	}
	
	public String bytype() throws Exception{
		beans = service.getsByType(bean.getDepartmentType());
		return BEANLIST;
	}
	
	
	
	
	public String update2() throws Exception{
		service.update(bean,usedProps);
		return SUCCESS;
	}
	public Department getBean() {
		return bean;
	}

	public void setBean(Department bean) {
		this.bean = bean;
	}

	public Collection<Department> getBeans() {
		return beans;
	}

	public void setBeans(Collection<Department> beans) {
		this.beans = beans;
	}

	public DepartmentService getService() {
		return service;
	}

	@Resource
	public void setService(DepartmentService service) {
		this.service = service;	
		this.setDataProvider(service);
	}	
}
